import pandas as pd
from rouge import Rouge

number = 32787
label = pd.read_csv('datasets/bug-report-title/test.csv')
label = label['title'].tolist()[number]
origin_results = pd.read_csv('output/predictions/t5-small-bug-report-title-bs8-402-23/predictions-bs-100.csv').loc[
       number:number].values.tolist()[0]
deduplication_results = pd.read_csv('output/predictions/t5-small-bug-report-title-bs8-402-23/deduplication-rouge/predictions-bs-top10-clearsearched03.csv').loc[
       number:number].values.tolist()[0]

print("[label]{}".format(label))
print("10 results by deduplication(row index={}):".format(number))
print(100 * '-')
rouge = Rouge()
for hyp in deduplication_results[1:11]:
    if hyp == "":
        print('{:.4f}    {}'.format(0.0, hyp))
        continue
    # drop the index number
    _hyp = hyp[hyp.index(']') + 1:]
    score = rouge.get_scores(_hyp, label)[0]['rouge-l']['f']
    print('{:.4f}    {}'.format(score, hyp))


origin_scores_results = []
for idx, hyp in enumerate(origin_results[1:101]):
    score = rouge.get_scores(hyp, label)[0]['rouge-l']['f']
    origin_scores_results.append([score, "[{}]{}".format(idx, hyp)])

origin_scores_results = pd.DataFrame(origin_scores_results)
origin_scores_results.columns = ['score', 'hyp']
top_scores_results = origin_scores_results.sort_values(by='score', ascending=False).head(10)

print(100 * '-')
print("top 10 results from origin:")
print(100 * '-')
for idx, data in top_scores_results.iterrows():
    print("{:.4f}    {}".format(data['score'], data['hyp']))
print(100 * '-')